package com.drcoffee.drcoffeemall.controller;


import com.drcoffee.drcoffeemall.entry.Main1;
import com.drcoffee.drcoffeemall.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/main")
public class MainController {
    @Autowired
    private OrderService orderService;

    @GetMapping("/getMainData")
    public List<Main1> getMainData(@RequestParam("date1") String date1, @RequestParam("date2") String date2){
        SimpleDateFormat  dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        Date date11 =new Date();
        Date date22 =new Date();
        List<Main1> gives =  new ArrayList<>();
        try {
            date11 = dateFormat.parse(date1);
            Calendar cal = Calendar.getInstance();
            cal.setTime(date11);
            cal.set(Calendar.HOUR_OF_DAY, 0);
            cal.set(Calendar.MINUTE, 0);
            cal.set(Calendar.SECOND, 0);
            date11 = cal.getTime();

            date22 = dateFormat.parse(date2);
            cal.setTime(date22);
            cal.set(Calendar.HOUR_OF_DAY, 23);
            cal.set(Calendar.MINUTE, 59);
            cal.set(Calendar.SECOND, 0);
            cal.set(Calendar.MILLISECOND, 0);
            cal.add(Calendar.DAY_OF_MONTH, 1);
            date22 = cal.getTime();
            System.out.println("9999999999999999999999"+orderService.getMainData(date11, date22));
            gives =  orderService.getMainData(date11, date22);

        } catch (ParseException e) {
            e.printStackTrace();
        }

        return gives;
    }
}
